import React, { PureComponent } from 'react'
import { Form, Table } from 'antd'
import { connect } from 'dva'
import styles from './Index.less'

// import { getValue } from '@/utils/utils'
@connect(({ loading, propCheckTable }) => ({
  propCheckTable,
  loading: loading.models.propCheckTable,
}))
@Form.create()
export default class List extends PureComponent {
  // 表格动作触发事件
  handleListChange = (pg, filtersArg, sorter) => {
    const { dispatch } = this.props
    const { formValues, pagination } = this.props.propCheckTable
    if (sorter.field && pagination.currentPage === pg.current) {
      return
    }

    const params = {
      ...formValues,
      current: pg.current,
      // size: pg.pageSize,
    }
    dispatch({
      type: 'propCheckTable/fetchList',
      payload: {
        ...params,
        // type: 3,
      },
    })
  }

  render() {
    const { loading } = this.props
    const { list, pagination } = this.props.propCheckTable

    const columns = [
      {
        title: '盘点单号',
        align: 'center',
        dataIndex: 'orderNo',
        width: 100,
        sorter: (a, b) => a.orderNo && a.orderNo.localeCompare(b.orderNo),
        sortDirections: ['descend', 'ascend'],
      },
      {
        title: '盘点单名称',
        align: 'center',
        dataIndex: 'pdJobName',
        width: 80,
      },
      {
        title: '盘点负责人',
        align: 'center',
        dataIndex: 'pdOperatorName',
        width: 70,
      },
      {
        title: '开始时间',
        align: 'center',
        dataIndex: 'pdStartDate',
        width: 80,
      },
      {
        title: '结束时间',
        align: 'center',
        dataIndex: 'pdEndDate',
        width: 80,
      },
      {
        title: '资产数量',
        align: 'center',
        dataIndex: 'zcCount',
        width: 80,
      },
      {
        title: '实际数量',
        align: 'center',
        dataIndex: 'factCount',
        width: 80,
      },
      {
        title: '差异数量',
        align: 'center',
        dataIndex: 'diffCount',
        width: 80,
      },
    ]

    return (
      <div className={styles.standardTable}>
        <Table
          loading={loading}
          size="small"
          bordered
          dataSource={list}
          rowKey={record => record.id}
          pagination={pagination}
          columns={columns}
          onChange={this.handleListChange}
          // scroll={{ x: 800 }}
        />
      </div>
    )
  }
}
